<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>用户修改</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="css/mui.min.css">
		<!--App自定义的css-->
		<!--<link rel="stylesheet" type="text/css" href="css/app.css"/>-->

	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">用户编辑</h1>
		</header>
		<div class="mui-content">
			<div class="mui-card">
				<ul class="mui-table-view">
					<li class="mui-table-view-cell">
						<div class="mui-collapse-content">
							<form class="mui-input-group">
								<div class="mui-input-row">
									<label>账号：</label>
									<input type="text" id="Account" placeholder="请输入账号">
								</div>
								<div class="mui-input-row">
									<label>昵称：</label>
									<input type="text" id="UserName" class="mui-input-clear" placeholder="请输入昵称">
								</div>
								<div class="mui-input-row">
									<label>密码：</label>
									<input type="password" id="Pwd" value="" class="mui-input-clear"
										placeholder="请输入密码">
								</div>
								<div class="mui-button-row">
									<button class="mui-btn mui-btn-primary" type="button"
										onclick="User_Save();">保存</button>&nbsp;&nbsp;
									<button class="mui-btn mui-btn-danger" style="display: none;" id="btnDel"
										type="button" onclick="User_Del();">删除</button>&nbsp;&nbsp;
									<button class="mui-btn" type="button"
										onclick="Core.Tool.Back()">取消</button>
								</div>
							</form>
						</div>
					</li>
				</ul>
			</div>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/jquery.min.js"></script>
		<script src="libs/lib.js"></script>
		<script>
			var Model = {};
			var isAdd = true;

			mui.init({
				swipeBack: true //启用右滑关闭功能
			});

			Page_Init();

			function Page_Init() {
				User_Get_Info();
				if (isAdd == false)
					document.getElementById("btnDel").style.display = "";
			}

			function User_Get_Info() {
				var param = Core.Tool.QueryUrlString("id");
				if (param && param.id) {
					isAdd = false;
					Core.Post("User/GetModel", param, function(result, status) {
						if (result.errorMsg) {
							Core.Msg.Alert(result.errorMsg);
							return;
						}
						Model = result.data;
						document.getElementById("Account").value = Model.account;
						document.getElementById("UserName").value = Model.userName;
					});
				}
			}

			function User_Save() {
				var url = Model && Model.id ? "User/Edit" : "User/Add";
				Model.account = document.getElementById("Account").value;
				Model.userName = document.getElementById("UserName").value;
				Model.pwd = document.getElementById("Pwd").value;
				Core.Post(url, {
					Param: Model
				}, function(result, status) {
					if (result.errorMsg) {
						Core.Msg.Alert(result.errorMsg);
						return;
					}
					Core.Tool.Back();
				});
			}

			function User_Del() {
				Core.Msg.Confirm("您确定要删除该用户吗？", null, null, function(e) {
					if (e.index != 1) {
						return;
					}
					if (!Model) {
						return;
					}
					Core.Post("User/Del", {
						id: Model.id
					}, function(result, status) {
						if (result.errorMsg) {
							Core.Msg.Alert(result.errorMsg);
							return;
						}
						Core.Tool.Back();
					});
				})
			}
		</script>
	</body>

</html>